package com.yzh.wanandroid.component.fragment

import android.view.View
import androidx.navigation.Navigation
import com.yzh.wanandroid.R
import com.yzh.wanandroid.StartNavigationDirections
import com.yzh.wanandroid.base.MvvmFragment
import com.yzh.wanandroid.databinding.FragmentSettingBinding
import com.yzh.wanandroid.vm.SettingFragmentVm

class SettingFragment :
    MvvmFragment<FragmentSettingBinding, SettingFragmentVm>() {

    private val TAG = "SettingFragment"

    override fun initViewModel(): SettingFragmentVm = createViewModel()

    override fun getLayoutId() = R.layout.fragment_setting

    override fun initView(view: View) {
        initTitle()
    }

    private fun initTitle() {
        mBinding.run {
            settingTitle.titleText.setText(R.string.setting)
            settingTitle.toolbar.navigationIcon =
                requireActivity().getDrawable(R.drawable.arrow_back)
            settingTitle.toolbar.setNavigationOnClickListener {
                requireActivity().onBackPressed()
            }
        }
    }

    override fun initData() {
        initBinding()
    }

    private fun initBinding() {
        mBinding.run {
            fragment = this@SettingFragment
            viewModel = mViewModel
        }
    }

    fun toWebInfo(view: View, url: String, title: String) {
        Navigation.findNavController(view).navigate(StartNavigationDirections.toWebInfo(url, title))
    }
}